package app.server.project.main.service.db.entity.cfg;

import app.server.project.core.constants.Def;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "race_cfg")
@TableName("race_cfg")
@Comment(value = "级别信息配置表")
public class RaceCfgEntity {

    @Id
    @Column(name = "id")
    @Comment("赛道id")
    @TableId("id")
    private int id;


    @Column(name = "name")
    @Comment("名称")
    @TableField("name")
    private String name;

    /**
     * 解锁等级
     */
    @Column(name = "lv_lock")
    @Comment("解锁等级")
    @TableField("lv_lock")
    private int lvLock;
    /**
     * 代币比率
     */
    @Column(name = "rate")
    @Comment("代币比率")
    @TableField("rate")
    @JsonSerialize(using = ToStringSerializer.class)
    private long rate;

    @Column(name = "chance")
    @Comment("爆率")
    @TableField("chance")
    private int chance;

    @Column(name = "produce")
    @Comment("产出")
    @TableField("produce")
    @JsonSerialize(using = ToStringSerializer.class)
    private long produce;

    @Column(name = "consume_energy")
    @Comment("体力消耗")
    @TableField("consume_energy")
    private int consumeEnergy;

    /**
     * 邀请人数
     */
    @Column(name = "invite_num_cfg")
    @Comment("邀请人数")
    @TableField("invite_num_cfg")
    private int inviteNumCfg;
    /**
     * 提现金额
     */
    @Column(name = "withdraw_amount")
    @Comment("提现金额")
    @TableField("withdraw_amount")
    private long withdrawAmount;


    /**
     * 提现金额
     */
    @Column(name = "free_num")
    @Comment("免费次数")
    @TableField("free_num")
    private long freeNum;


    @Column(name = "order_index")
    @Comment("排序")
    @TableField("order_index")
    private int orderIndex;

    @Column(name = "start_time")
    @Comment("开始时间")
    @TableField("start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "end_time")
    @Comment("结束时间")
    @TableField("end_time")
    private LocalDateTime endTime;


    @Column(name = "free_status")
    @Comment("免费状态")
    @TableField("free_status")
    private int freeStatus;

    @Column(name = "withdraw_status")
    @Comment("提现状态")
    @TableField("withdraw_status")
    private int withdrawStatus;

    @Column(name = "logo_url")
    @Comment("代币logo名称")
    @TableField("logo_url")
    private String logoUrl;

    @Column(name = "race_name_url")
    @Comment("赛道名称图标")
    @TableField("race_name_url")
    private String raceNameUrl;

    @JsonSerialize(using = ToStringSerializer.class)
    @Column(name = "exchange")
    @Comment("汇率")
    @TableField("exchange")
    private long exchange;

    @Column(name = "exchange_rate")
    @Comment("汇率倍率")
    @TableField("exchange_rate")
    @JsonSerialize(using = ToStringSerializer.class)
    private long exchangeRate;

    public long getFreeNum() {
        if (Def.Zero >= this.freeNum) {
            return 30;
        }
        return freeNum;
    }
}
